package com.boot.main.utils;

public class StringUtil {
    private StringUtil(){}
    private static final char UNDERLINE = '_';
    public static boolean isBlank(String str){
        return str == null || "".equals(str.trim());
    }
    public static boolean isNotBlank(String str){
        return !isBlank(str);
    }
    public static boolean isNull(byte[] bytes){
        return bytes == null || bytes.length == 0;
    }
    public static boolean isNotNull(byte[] bytes){
        return !isNull(bytes);
    }
    public static String camelToUnderline(String param){
        if(isNotBlank(param)){
            int len = param.length();
            StringBuilder sb = new StringBuilder(len);
            for(int i=0; i<len; i++){
                char c = param.charAt(i);
                if(Character.isUpperCase(c)){
                    sb.append(UNDERLINE);
                    sb.append(Character.toLowerCase(c));
                }else{
                    sb.append(c);
                }
            }
            return sb.toString();
        } else {
            return "";
        }
    }
    public static String underlineToCamel(String param) {
        if (isNotBlank(param)) {
            int len = param.length();
            StringBuilder sb = new StringBuilder(len);
            for (int i = 0; i < len; i++) {
                char c = param.charAt(i);
                if (c == 95) {
                    i++;
                    if (i < len) {
                        sb.append(Character.toUpperCase(param.charAt(i)));
                    }
                } else {
                    sb.append(c);
                }
            }
            return sb.toString();
        } else {
            return "";
        }
    }

    public static String addSingleQuotes(String param){
        return "\'" + param + "\'";
    }
}
